﻿// CIOInputDlg.cpp: 实现文件
//

#include "pch.h"
#include "SP.h"
#include "CIOInputDlg.h"
#include "afxdialogex.h"


// CIOInputDlg 对话框

IMPLEMENT_DYNAMIC(CIOInputDlg, CDialogEx)

CIOInputDlg::CIOInputDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DLG_IO_INPUT, pParent)
{

}

CIOInputDlg::~CIOInputDlg()
{
}

void CIOInputDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BOOL CIOInputDlg::OnInitDialog()
{
	SetTimer(TIMER_ID_IO_CONTROL_STATUS_IN, 50, NULL);
	ChangeIoTextIn();
	SetIOStatus();
	
	return TRUE;
}

void CIOInputDlg::OnCancel()
{
	KillTimer(TIMER_ID_IO_CONTROL_STATUS_IN);
	CDialogEx::OnCancel();
}

void CIOInputDlg::SetIOStatus()
{
	CButton* pCheck = nullptr;
	pCheck = (CButton*)GetDlgItem(IDC_CIS0);  pCheck->SetCheck(Manager.GetCio()->S00);
	pCheck = (CButton*)GetDlgItem(IDC_CIS1);  pCheck->SetCheck(Manager.GetCio()->S01);
	pCheck = (CButton*)GetDlgItem(IDC_CIS2);  pCheck->SetCheck(Manager.GetCio()->S02);
	pCheck = (CButton*)GetDlgItem(IDC_CIS3);  pCheck->SetCheck(Manager.GetCio()->S03);
	pCheck = (CButton*)GetDlgItem(IDC_CIS4);  pCheck->SetCheck(Manager.GetCio()->S04);
	pCheck = (CButton*)GetDlgItem(IDC_CIS5);  pCheck->SetCheck(Manager.GetCio()->S05);
	pCheck = (CButton*)GetDlgItem(IDC_CIS6);  pCheck->SetCheck(Manager.GetCio()->S06);
	pCheck = (CButton*)GetDlgItem(IDC_CIS7);  pCheck->SetCheck(Manager.GetCio()->S07);
	pCheck = (CButton*)GetDlgItem(IDC_CIS8);  pCheck->SetCheck(Manager.GetCio()->S08);
	pCheck = (CButton*)GetDlgItem(IDC_CIS9);  pCheck->SetCheck(Manager.GetCio()->S09);
	pCheck = (CButton*)GetDlgItem(IDC_CIS10);  pCheck->SetCheck(Manager.GetCio()->S10);
	pCheck = (CButton*)GetDlgItem(IDC_CIS11);  pCheck->SetCheck(Manager.GetCio()->S11);
	pCheck = (CButton*)GetDlgItem(IDC_CIS12);  pCheck->SetCheck(Manager.GetCio()->S12);
	pCheck = (CButton*)GetDlgItem(IDC_CIS13);  pCheck->SetCheck(Manager.GetCio()->S13);
	pCheck = (CButton*)GetDlgItem(IDC_CIS14);  pCheck->SetCheck(Manager.GetCio()->S14);
	pCheck = (CButton*)GetDlgItem(IDC_CIS15);  pCheck->SetCheck(Manager.GetCio()->S15);
	pCheck = (CButton*)GetDlgItem(IDC_CIS16);  pCheck->SetCheck(Manager.GetCio()->S16);
}

void CIOInputDlg::ChangeIoTextIn()
{
	std::vector<IO_MODULE> vIoMap;
	vIoMap = *Config.GetIOInputSetting();
	for (int i = 0; i < 14; i++)
	{
		CWnd * pStatic = nullptr;

		pStatic = (CWnd*)GetDlgItem(IDC_STATIC_TIS0 + i);//控件编号问题
		CString cstr;
		cstr.Format(L"%d_", i);
		cstr.Append(vIoMap[i].m_cstrDescription);
		pStatic->SetWindowTextW(cstr);

	}
}


BEGIN_MESSAGE_MAP(CIOInputDlg, CDialogEx)
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CIOInputDlg 消息处理程序


void CIOInputDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (nIDEvent == TIMER_ID_IO_CONTROL_STATUS_IN)
	{
		SetIOStatus();
	}

	CDialogEx::OnTimer(nIDEvent);
}
